<template>
  <div>
    <i-frame :src="reportUrl" />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { getToken } from '@/utils/auth'
import iFrame from '@/components/iFrame/index'
import { ElMessage } from 'element-plus' // 需要弹窗提示的话

const reportUrl = ref('')
const route = useRoute()

onMounted(() => {
  let query = route.query
  let code = undefined
  let paramsString = ''

  if (query) {
    for (const key in query) {
      if (Object.hasOwnProperty.call(query, key)) {
        const param = query[key]
        if (key === 'code') {
          code = param
        } else {
          if (paramsString !== '') {
            paramsString += '&' + key + '=' + param
          } else {
            paramsString = '&' + key + '=' + param
          }
        }
      }
    }
  }

  if (code) {
    reportUrl.value = `${import.meta.env.VITE_APP_BASE_API}/jmreport/view/${code}?token=Bearer ${getToken()}${paramsString}`
  } else {
    ElMessage.error('报表编码(code)为空，无法打开报表')
  }
})
</script>

<script>
export default {
  name: 'PyJeecgReportView',
  components: { iFrame }
}
</script>
